﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Text;
using System.Web.UI;
using System.Web.UI.WebControls;
using Ivony.Fluent;
using Ivony.Html;
using Ivony.Html.Parser;

using ihongma.WebData;

namespace ihongma.test
{
    public partial class uisdc : System.Web.UI.Page
    {
        JumonyParser parser = new JumonyParser();
        testUISDC uisdcS = new testUISDC();
        protected void Page_Load(object sender, EventArgs e)
        {
            uisdcS.url(2, 357, "http://www.uisdc.com/category/uiicon/page/");
            //for (int i = 0; i < 12; i++)
            //{
            //    url(i, 357, "http://www.uisdc.com/category/uiicon/page/");
            //}
           // pageinfo("http://www.uisdc.com/flat-design", "sdsasa");
        }
        public void url(int j, int category_id,string url)
        {
            string showhtml = HttpRequestHelper.GetPageSourceByUrl(url+j.ToString(), "utf-8");
            var dataDocument = parser.Parse(showhtml);
            var items = dataDocument.Find(".post-title a").ToArray();
            var tempitems = dataDocument.Find(".entry-summary").ToArray();
            var thumbnai = dataDocument.Find(".archive-thumbnail").ToArray();
            for (int i = 0; i < items.Count(); i++)
            {
                pageinfo(items[i].Attribute("href").Value(), tempitems[i].InnerText(), category_id, thumbnai[i].Attribute("src").Value());
    
            }
        }
        public void pageinfo(string usrl, string temp, int category_id,string img)
        {
            //StringBuilder sb = new StringBuilder();
            string showhtml = HttpRequestHelper.GetPageSourceByUrl(usrl, "utf-8");
            var dataDocument = parser.Parse(showhtml);
            var items = dataDocument.Find(".post-content");
           // items.Find(".similarity .wumii-hook .ad .post-copyright").Remove();
            items.Find(".entry-content div").Reverse().Take(6).Remove();
            items.Find(".entry-content p").Reverse().Take(2).Remove();
            items.Find("[alt='youshege']").Reverse().Take(1).Remove();
            // items.Find("blockquote").Reverse().Take(1).Remove();
             
           
           
           
                com.ihongma.www.addserver add = new com.ihongma.www.addserver();
                com.ihongma.www.article ar = new com.ihongma.www.article()
                {
                    add_time = DateTime.Parse(dataDocument.Find(".published").Single().InnerText()),
                    author = "colt",
                    category_id = category_id,
                    channel_id = 1,
                    zhaiyao = temp,
                    click = 100,
                    content = items.Find(".entry-content").Single().ToString().Replace("优设网","鸿马网").Replace("uisdc.com","ihongma.com"),
                    //dataDocument.Find("#artical_real p").ElementAt(0).InnerHtml() + "<p>" + temp + "</p>",

                    title = dataDocument.Find(".post-title").Single().InnerText(),
                    digg_act = 0,
                    digg_good = 0,
                    form = "鸿马",
                    img_url = img,
                    is_hot = 0,
                    is_lock = 0,
                    is_msg = 0,
                    is_red = 0,
                    is_slide = 0,
                    is_top = 0,
                    seo_description = temp,
                    seo_keywords = dataDocument.Find(".post-title").Single().InnerText(),
                    seo_title = dataDocument.Find(".post-title").Single().InnerText(),
                    sort_id = 99,
                    link_url = ""

                };
                add.addnews(ar, "s123456");
            
        }
    }
}